{extend name="admin@public/basic" /}
{block name="style"}{/block}
<link rel="stylesheet" href="__STATIC__/css/admin/public.css" media="all"/>
{block name="cotent"}
<form class="layui-form" style="width:80%;">
    <br>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">管理账号</label>
        <div class="layui-input-block">
            <input type="text" name="username" class="layui-input username" lay-verify="required" value="{$user.username|default=''}" placeholder="请输入管理账号">
        </div>
    </div>

    {if empty($user)}
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">初始密码</label>
        <div class="layui-input-block">
            <input type="password" name="password" class="layui-input password" lay-verify="required" placeholder="请输入初始密码">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-block">
            <input type="password" name="password1" class="layui-input password1" lay-verify="required" placeholder="请输入确认密码">
        </div>
    </div>
    {/if}

    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">手机</label>
        <div class="layui-input-block">
            <input type="text" name="phone" class="layui-input phone" value="{$user.phone|default=''}" placeholder="请输入手机">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">QQ</label>
        <div class="layui-input-block">
            <input type="text" name="qq" class="layui-input qq" value="{$user.qq|default=''}" placeholder="请输入QQ">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="email" name="mail" class="layui-input mail" value="{$user.mail|default=''}" placeholder="请输入邮箱">
        </div>
    </div>


    <div class="layui-form-item layui-row">
        <label class="layui-form-label">用户权限</label>
        <div class="layui-input-block">
            {foreach auth as $vo}
            <input type="checkbox" name="auth_id" class="layui-input auth_id" value="{$vo.id|default=''}" lay-skin="primary" title="{$vo.title|default=''}" {eq name='$vo.is_checked|default=false' value='true' }checked{/eq}>
            {/foreach}

        </div>
    </div>

    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">备注信息</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入备注信息" name="remark" class="layui-textarea remark">{$user.remark|default=''}</textarea>
        </div>
    </div>

    {if !empty($user)}
    <input type="hidden" class="id" name="id" value="{$user.id|default=''}">
    {/if}

    <div class="layui-form-item layui-row layui-col-xs12">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-sm" lay-submit="" id="addUser">确定</button>
            <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary">取消</button>
        </div>
    </div>
</form>
{/block}

{block name="script"}
<script>
    layui.use(['form', 'layer'], function () {
        var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery;

        /**
         * 新增以及编辑后台用户
         */
        $("#addUser").click(function () {
            var url = '{if empty($user)}{:url("$thisClass/add")}{else/}{:url("$thisClass/edit")}{/if}';
            var auth_id = [];
            $("input:checkbox[name='auth_id']:checked").each(function () {
                auth_id.push($(this).val());
            });
            var data = {
                id: $(".id").val(),
                username: $(".username").val(),
                password: $(".password").val(),
                password1: $(".password1").val(),
                phone: $(".phone").val(),
                qq: $(".qq").val(),
                mail: $(".mail").val(),
                auth_id: auth_id,
                remark: $(".remark").val(),
            };
            $.request.post(url, data, function (res) {
                $.msg.success(res.msg, function () {
                    $.tool.reload();
                });
            });
            return false;
        });

    })
</script>
{/block}
